#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1010;

LL n, k;
LL q[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        cin >> n >> k;

        for(int i = 0; i < k; i ++) q[i] = 0;
        LL res = 0;

        for(int i = 1, x; i <= n; i ++){
            cin >> x;

            res = res + x / k;
            q[x % k] ++;
        }

        int i = 0, j = k - 1;
        while(i <= j){
            if(i == j){
                if(i * 2 < k){
                    break;
                }else{
                    res += q[i] / 2;
                    q[i] = 0;
                    break;
                }
            }

            if(q[i] == 0){
                i ++;
                continue;
            }else if(q[j] == 0){
                j --;
                continue;
            }else{
                if(i + j < k){
                    q[i] = 0;
                    i ++;
                }else{
                    if(q[i] == q[j]){
                        res = res + q[i];
                        q[i] = q[j] = 0;
                        i ++, j --;
                    }else if(q[i] > q[j]){
                        res = res + q[j];
                        q[i] -= q[j];
                        j --;
                    }else{
                        res = res + q[i];
                        q[j] -= q[i];
                        i ++;
                    }
                }
            }
        }

        cout << res << '\n';
    }


    return 0;
}